import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  server: {
    proxy: {
      // 代理管理员API请求到后端（只代理API，不代理前端页面路由）
      '/admin/auth': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/user/list': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/user/detail': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/user/status': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/user/resetPassword': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/user/delete': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/product': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/order': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/post': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/comment': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/admin/dashboard/': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/dashboard': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/user': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/product': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/cart': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/order': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/favorite': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/fish': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/post': {
        target: 'http://localhost:8080',
        changeOrigin: true
      },
      '/comment': {
        target: 'http://localhost:8080',
        changeOrigin: true
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src') // 配置 @ 指向 src 目录
    }
  }
})